<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="./calculator.js"></script>
    <!-- 引入bootstrap5 -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
    <title>简易计算器</title>
    <style>
        .calculator {
            max-width: 300px;
            margin: 50px auto;
            border: 1px solid #ddd;
            border-radius: 10px;
            overflow: hidden;
        }
        .calculator .display {
            padding: 8px;
            font-size: 2em;
            text-align: right;
        }
        .calculator button {
            padding: 0;
            font-size: 30px;
            aspect-ratio: 1 / 1; /* 确保按钮为正方形 */
            border: none; /* 去掉边框 */
            outline: none; /* 去掉聚焦时的外边框 */
            background-color: #f9f9f9;
            transition: background-color 0.3s;
        }
        .calculator button:hover {
            background-color: #d6d6d69d;
        }
        .calculator .buttons {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 0; /* 去掉按钮之间的空隙 */
        }
        .calculator .buttons button:nth-child(4n+1),
        .calculator .buttons button:nth-child(4n+2),
        .calculator .buttons button:nth-child(4n+3) {
            border-right: 1px solid #ddd;
        }
        .calculator .buttons button:nth-child(-n+4) {
            border-bottom: 1px solid #ddd;
        }
        .calculator .buttons button:nth-child(n+5):nth-child(-n+8) {
            border-bottom: 1px solid #ddd;
        }
        .calculator .buttons button:nth-child(n+9):nth-child(-n+12) {
            border-bottom: 1px solid #ddd;
        }
        .calculator .buttons button:nth-child(n+13):nth-child(-n+16) {
            border-bottom: 1px solid #ddd;
        }
        .calculator .buttons button:nth-child(n+17):nth-child(-n+20) {
            border-bottom: 1px solid #ddd;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="card calculator">
            <div class="card-header">
                <h4 class="card-title">简易计算器</h4>
            </div>
            <div class="card-body">
                <div class="display" id="display_s" style="font-size: 15px;">0</div>
                <div class="display" id="display">0</div>
                <div class="container buttons row-col-4">
                    <button id="clearButton" style="background-color: #ff000050;" class="col" onclick="clearDisplay()">C</button>
                    <button class="col" onclick="toggleSign()">±</button>
                    <button class="col" onclick="setOperation('%')">%</button>
                    <button class="col" onclick="setOperation('/')">\</button>
                    <button class="col" onclick="appendNumber('7')">7</button>
                    <button class="col" onclick="appendNumber('8')">8</button>
                    <button class="col" onclick="appendNumber('9')">9</button>
                    <button class="col" onclick="setOperation('*')">*</button>
                    <button class="col" onclick="appendNumber('4')">4</button>
                    <button class="col" onclick="appendNumber('5')">5</button>
                    <button class="col" onclick="appendNumber('6')">6</button>
                    <button class="col" onclick="setOperation('-')">-</button>
                    <button class="col" onclick="appendNumber('1')">1</button>
                    <button class="col" onclick="appendNumber('2')">2</button>
                    <button class="col" onclick="appendNumber('3')">3</button>
                    <button class="col" onclick="setOperation('+')">+</button>
                    <button class="col" onclick="appendNumber('00')">00</button>
                    <button class="col" onclick="appendNumber('0')">0</button>
                    <button class="col" onclick="appendDecimal()">.</button>
                    <button class="col" onclick="calculateResult()">=</button>
                </div>
            </div>
        </div>
    </div>

</body>
</html>